from pybotx import (
    Bot,
    BubbleMarkup,
    ChatCreatedEvent,
    HandlerCollector,
    IncomingMessage,
)

from app.resources import strings


collector = HandlerCollector()

@collector.default_message_handler
async def default_message_handler(
    message: IncomingMessage,
    bot: Bot,
) -> None:
    
    bubbles = BubbleMarkup()
    bubbles.add_button(command="/menu", label="Главное меню")

    await bot.send_message(body=strings.DEFAULT_MESSAGE, bubbles=bubbles)


@collector.chat_created
async def chat_created_handler(event: ChatCreatedEvent, bot: Bot) -> None:
    
    answer_body = strings.CHAT_CREATED_TEMPLATE.format(
        bot_project_name=strings.BOT_DISPLAY_NAME
    )
    bubbles = BubbleMarkup()
    bubbles.add_button(command="/menu", label="Главное меню")

    await bot.send_message(answer_body, bubbles=bubbles)


@collector.command("/menu")
async def menu_handler(message: IncomingMessage, bot: Bot)  -> None:

    bubbles = BubbleMarkup()
    bubbles.add_button(command="/news", label="Новости дирекции качества")
    bubbles.add_button(command="/fidback", label="Статистика КН и АИК")
    bubbles.add_button(command="/kpi", label="Оставить обратную связь")

    await bot.send_message(body=strings.MAIN_MENU, bubbles=bubbles)

